<template>
<view v-show="searchDrawer" class="searchDrawer" :style="{heigth:drawerHeight}">
    <!-- 筛选框 -->
    <view class="content">
        <view class="search_box">
            <uni-list class="center-list">
                <uni-list-item :showArrow="true" title="举办时间">
                    <!-- 自定义 footer-->
                    <template slot="footer">
                        <view class="item-footer" style="width:70%">
                            <uni-datetime-picker v-model="getQuery.event_date" type="daterange" rangeSeparator="至" />
                        </view>
                    </template>
                </uni-list-item>
                <uni-list-item :showArrow="true" title="签单时间">
                    <!-- 自定义 footer-->
                    <template slot="footer">
                        <view class="item-footer" style="width:70%">
                            <uni-datetime-picker v-model="getQuery.sign_date" type="daterange" format="yyyy/mm/dd" rangeSeparator="至" />
                        </view>
                    </template>
                </uni-list-item>
            </uni-list>
        </view>
        <view class="scroll_height ">
            <view class="search_box">
                <uni-list class="center-list">
                    <uni-list-item :showArrow="true" title="选择员工" clickable @click="showUserDialog">
                        <!-- 自定义 footer-->
                        <template slot="footer">
                            <view class="item-footer">
                                <text>请选择</text>
                            </view>
                        </template>
                    </uni-list-item>
                    <view class="get-new-list" v-if="userTitle.length>0">
                        <uni-tag-ext @click="closableUserTag(index)" class="tag-list" v-for="(item,index) in userTitle" :key="index" :text="item.title" type="primary" size="small" :closable="true"></uni-tag-ext>
                    </view>
                    <uni-list-item :showArrow="true" title="选择酒店" clickable @click="showSearchDialog">
                        <!-- 自定义 footer-->
                        <template slot="footer">
                            <view class="item-footer" style="width:70%">
                                <text>请选择</text>
                            </view>
                        </template>
                    </uni-list-item>
                    <view class="get-new-list" v-if="hotelTitle.length>0">
                        <uni-tag-ext @click="closableHotelTag(index)" class="tag-list" v-for="(item,index) in hotelTitle" :key="index" :text="item.title" type="primary" size="small" :closable="true"></uni-tag-ext>
                    </view>
                    <uni-list-item :showArrow="true" title="签单公司" clickable @click="showCompanyDialog">
                        <!-- 自定义 footer-->
                        <template slot="footer">
                            <view class="item-footer">
                                <text>请选择</text>
                            </view>
                        </template>
                    </uni-list-item>
                    <view class="get-new-list" v-if="companTitle.length>0">
                        <uni-tag-ext @click="closableCompanTag(index)" class="tag-list" v-for="(item,index) in companTitle" :key="index" :text="item.title" type="primary" size="small" :closable="true"></uni-tag-ext>
                    </view>
                </uni-list>
            </view>
            <view class="search_box">
                <view class="search_list">
                    <view class="search_title">审核状态</view>
                    <view class="search_type">
                        <view class="view_box" v-for="(item, index) in auditStatus" :key="index" :class="{ 'actived':getQuery.check_status.indexOf(item.id)>-1}" @click="toggleStatus(item.id)">
                            <text>{{ item.title }}</text>
                        </view>
                    </view>
                </view>
            </view>
            <view class="search_box">
                <view class="search_list">
                    <view class="search_title">结算信息</view>
                    <view class="search_type">
                        <view class="view_box" v-for="(item, index) in settlementStatus" :key="index+'settlement'" :class="{ 'actived':getQuery.settlement_status.indexOf(item.id)>-1}" @click="toggleSettlement(item.id)">
                            <text>{{ item.title }}</text>
                        </view>
                    </view>
                </view>
            </view>
            <view class="search_box">
                <view class="search_list">

                    <view class="search_title">信息类型</view>
                    <view class="search_type">
                        <view class="view_box" v-for="(item, index) in newsTypeList" :key="index" :class="{ 'actived':getQuery.news_type.indexOf(item.id)>-1}" @click="toggleNewsType(item.id)">
                            <text>{{ item.title }}</text>
                        </view>
                    </view>
                </view>
            </view>
            <view class="search_box">
                <view class="search_list">
                    <view class="search_title">合作模式</view>
                    <view class="search_type">
                        <view class="view_box" v-for="(item, index) in cooperationModeList.slice(0,4)" :key="index" :class="{ 'actived':getQuery.cooperation_mode.indexOf(item.id)>-1}" @click="toggleCooperation(item.id)">
                            <text>{{ item.title }}</text>
                        </view>
                    </view>
                </view>
            </view>
        </view>

    </view>
    <view class="btn">
        <button type="default" class="reset" @click="close">关闭</button>
        <button type="default" class="reset" @click="reset">重置</button>
        <button type="default" class="save" @click="doSearch()">搜索</button>
    </view>

    <hs-search :appendToBody="true" :getSelected="getSelectedHotel" ref="searchDialog"></hs-search>
    <dd-search :appendToBody="true" :getSelected="getSelectedCompany" ref="ddSearch"></dd-search>
</view>
</template>

<script>
import request from '@/utils/sun.js';
import dictionary from '@/utils/dictionary.js';
import orderCfg from '@/config/order.js';

export default {
    name: "my",
    props: {
        getQuery: {
            type: Object,
            default () {
                return {}
            }
        },
        type: "",
        pagination: {},
        listData: {
            type: Array,
            default: []

        }
    },
    computed: {
        //信息类型
        newsTypeList() {
            return dictionary.getPicker('newsTypeList')
        },
        //签单公司
        companyList() {
            return dictionary.getPicker('companyList')
        },

        cooperationModeList() {
            return dictionary.getPicker('cooperationModeList')
        },
        //审核状态
        auditStatus() {
            return orderCfg.auditStatus
        },
        //结算状态
        settlementStatus() {
            return orderCfg.settlementOfStatus
        },
        //订单性质
        orderNature() {
            return orderCfg.orderNature
        }
    },
    data() {
        let drawerHeight = window.innerHeight;
        return {
            newsTypeTitel: "",
            drawerHeight: drawerHeight,
            user: '', //个人信息
            userList: [],
            newstypeid: '',
            param: {
                hotel: "",
                company: ""
            },
            companTitle: [],
            searchIds: [],
            userTitle: [],
            hotelTitle: [],
            searchDrawer: false
        };
    },
    beforeMount() {
        this.dictionary = dictionary;
    },
    methods: {
        showDialogOpen() {
            this.searchDrawer = true;
            console.log(this.drawerHeight)

        },
        //取消酒店
        closableUserTag(index) {
            let _this = this;
            _this.userTitle.splice(index, 1);
        },
        closableHotelTag(index) {
            let _this = this;
            _this.hotelTitle.splice(index, 1);
        },
        closableCompanTag(index) {
            let _this = this;
            _this.companTitle.splice(index, 1);
        },

        // 显示搜索
        showSearchDialog() {
            this.$refs['ddSearch'].showSearchDialog('hotel');
        },
        //显示签单公司
        showCompanyDialog() {
            this.$refs['ddSearch'].showSearchDialog('company', this.searchIds);
        },
        //显示员工
        showUserDialog() {
            this.$refs['ddSearch'].showSearchDialog('user');
        },
        getSelectedCompany(ids, type, selectedGetTitles) {
            let _this = this;
            _this.searchIds = ids;
            if (type == 'company') {
                if (this.companTitle.length > 0) {
                    let selectedTitel = selectedGetTitles;
                    let baseTitel = _this.companTitle;
                    let concatData = selectedTitel.concat(baseTitel);
                    const res = new Map();
                    let newList = (concatData.filter((concatData) => !res.has(concatData.id) && res.set(concatData.id, 1)))

                    _this.companTitle = [];
                    _this.companTitle.push(...newList);

                } else {
                    _this.companTitle.push(...selectedGetTitles);
                }
            }
            if (type == 'user') {
                if (this.userTitle.length > 0) {
                    let selectedTitel = selectedGetTitles;
                    let baseTitel = _this.userTitle;
                    let concatData = selectedTitel.concat(baseTitel);
                    console.log(concatData)
                    const res = new Map();
                    let newList = (concatData.filter((concatData) => !res.has(concatData.id) && res.set(concatData.id, 1)))

                    _this.userTitle = [];
                    _this.userTitle.push(...newList);

                } else {
                    _this.userTitle.push(...selectedGetTitles);
                }
            }
            if (type == 'hotel') {
                if (this.hotelTitle.length > 0) {
                    let selectedTitel = selectedGetTitles;
                    let baseTitel = _this.hotelTitle;
                    let concatData = selectedTitel.concat(baseTitel);
                    const res = new Map();
                    let newList = (concatData.filter((concatData) => !res.has(concatData.id) && res.set(concatData.id, 1)))

                    _this.hotelTitle = [];
                    _this.hotelTitle.push(...newList);

                } else {
                    _this.hotelTitle.push(...selectedGetTitles);
                }
            }
        },
        //获取酒店
        getHotelHallList(hotelId) {
            let that = this;
            request.request({
                url: '/api/dictionary.hall/index',
                showLoading: true,
                token: true,
                data: {
                    store_id: hotelId
                },
                success(res) {
                    if (res.code == 200) {
                        that.hallList = res.data.list;
                    }
                }
            });
        },
        getSelectedHotel(item) {
            this.getQuery.hotel_id = item.id;
            this.param.hotel = item.title;
            // 选择完酒店，获取酒店的厅列表
            if (item.id > 0) {
                this.getHotelHallList(item.id);
            }
        },
        //信息类型切换
        toggleNewsType(id) {
            let index = this.getQuery.news_type.indexOf(id);
            if (index > -1) {
                this.getQuery.news_type.splice(index, 1)
            } else {
                this.getQuery.news_type.push(id)
            }
        },
        toggleStatus(id) {
            let index = this.getQuery.check_status.indexOf(id);
            if (index > -1) {
                this.getQuery.check_status.splice(index, 1)
            } else {
                this.getQuery.check_status.push(id)
            }
        },
        toggleCooperation(id) {
            let index = this.getQuery.cooperation_mode.indexOf(id);
            if (index > -1) {
                this.getQuery.cooperation_mode.splice(index, 1)
            } else {
                this.getQuery.cooperation_mode.push(id)
            }
        },
        toggleOrder(id) {
            let index = this.getQuery.orderNature_id.indexOf(id);
            if (index > -1) {
                this.getQuery.orderNature_id.splice(index, 1)
            } else {
                this.getQuery.orderNature_id.push(id)
            }
        },
        toggleSettlement(id) {
            let index = this.getQuery.settlement_status.indexOf(id);
            if (index > -1) {
                this.getQuery.settlement_status=[]
            } else {
                this.getQuery.settlement_status = (id)
            }
        },
        //隐藏筛选框
        close() {
            this.searchDrawer = false;
            this.reset();
            this.$emit('getOrderList');
        },
        //选择审核状态
        selectStatus(index) {
            this.currentIndex = index;
            this.getQuery.check_status = this.auditStatus[this.currentIndex].id

        },
        selectnewsType(e) {
            let _this = this;
            let nesTypeIndex = e.detail.value;
            _this.getQuery.news_type = _this.newsTypeList[nesTypeIndex].id;
            _this.newsTypeTitel = _this.newsTypeList[nesTypeIndex].title;

        },
        //选择公司
        selectCompany(index) {
            let _this = this;
            _this.companyIndex = index;
            _this.getQuery.company_id = _this.companyList[_this.currentIndex].id
        },

        //重置
        reset() {

            this.getQuery.keyword = "";
            this.getQuery.company_id = []; //签单公司
            this.getQuery.news_type = []; //信息类型
            this.getQuery.check_status = []; //审核状态
            this.getQuery.cooperation_mode = []; //合作模式
            this.getQuery.settlement_status = []; //结算状态
            this.getQuery.orderNature_id = []; //订单性质
            this.getQuery.user_id = []; //员工
            this.getQuery.hotel_id = ""; //酒店
            this.getQuery.event_date = [];
            this.getQuery.sign_date = [];

            this.companTitle = [];
            this.hotelTitle = [];
            this.userTitle = [];
        },
        //筛选
        doSearch() {
            let _this = this;
            _this.getQuery.hotel_id = _this.hotelTitle.map(item => {
                return item.id
            })
            _this.getQuery.user_id = _this.userTitle.map(item => {
                return item.id
            })
            _this.getQuery.company_id = _this.companTitle.map(item => {
                return item.id
            })
            _this.pagination.page = 1;
            _this.$emit('getOrderList');

            _this.searchDrawer = false;

        },

    }
};
</script>

<style lang="less" scoped>
page {

    background: #f4f4f4;
    padding-top: 0;

    /deep/ .uni-date-x--border {

        border: none !important;

    }

    /deep/ .uni-drawer--right {
        -webkit-transform: translate3d(0, 0, 0);
        -moz-transform: translate3d(0, 0, 0);
        -ms-transform: translate3d(0, 0, 0);
        transform: translate3d(0, 0, 0);
    }

    /deep/ .uni-date__x-input {
        height: 20px !important;
        padding: 0;
    }

    /deep/.uniui-calendar:before {
        display: none;
    }

    /deep/.uni-picker-container,
    .uni-list-item {
        font-size: 14px;
    }

    // /deep/.uni-list-item__container {
    //     overflow: inherit;
    // }

    /deep/ .uni-date-editor--x .uni-date__icon-clear {
        top: -8px;
        right: -15px;
    }

    /deep/.uni-input-input {
        line-height: 20px
    }

    /deep/.container--right {
        overflow: inherit;
    }
}

.search_box {
    margin-bottom: 10px;
    background: white;
    padding-bottom: 10px;

    .get-new-list {
        padding: 5px;
        overflow: hidden;

        .tag-list {
            margin-right: 2px;
            margin-bottom: 2px;
        }
    }

    .item-footer {
        position: relative;
        text-align: right;
        display: block;
        width: 229px;
        font-size: 24upx;
        color: #666666;
        white-space: nowrap;
        text-overflow: ellipsis;

        .tag {
            display: inline-block;
            padding: 1px 4px;
            position: relative;
            margin-right: 2px;

            ::after {
                content: '';
                width: 1px;
                height: 10px;
                background: #a08989;
                position: absolute;
                top: 4px;
                right: -2px
            }

            // .tag:after{
            //     width: 1px;
            //     height: 1px;
            //     background: red;
            //     position: absolute;
            //     right: 0;
            //     top:0
            // }
        }

        .clearIcon {
            position: absolute;
            right: -20px;
            top: 3px;
        }
    }

    .search_content {
        padding: 10px;

    }
}

.top {
    width: 100%;
    // height: 150upx;
    background: #ffffff;
    padding: 10upx 0 10upx 19upx;
    box-sizing: border-box;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 10;

    .left {
        width: 50upx;
        height: 58upx;
        display: flex;
        align-items: center;
        float: left;

        image {
            width: 40upx;
            height: 40upx;
        }
    }

    .search {
        position: relative;
        width: 576upx;
        height: 58upx;
        margin-left: 10upx;
        float: left;

        input {
            width: 576upx;
            height: 58upx;
            background: rgba(255, 255, 255, 1);
            border: 1upx solid rgba(238, 238, 238, 1);
            border-radius: 10upx;
            padding-left: 1rem;
            box-sizing: border-box;
        }

        .searchIcon {
            position: absolute;
            right: 1rem;
            top: 50%;
            transform: translateY(-50%);
        }
    }

    .screen {
        width: 55upx;
        height: 58upx;
        font-size: 26upx;
        color: #406ceb;
        margin-left: 10upx;
        line-height: 58upx;
    }
}

/* 顶部tabbar */
.nav-bar {
    // position: fixed;
    // left: 0;
    // top:230upx;
    // z-index: 10;
    // height: 90upx;
    padding: 20upx 0;
    // line-height: 90upx;
    white-space: nowrap;
    box-shadow: 0 2upx 8upx rgba(0, 0, 0, 0.06);
    background-color: #fff;

    .uni-scroll-view-content {}

    .nav-item {
        display: inline-block;
        padding: 5px 20upx;
        text-align: center;
        font-size: 13px;
        color: #303133;
        position: relative;

        &:after {
            content: '';
            width: 0;
            height: 0;
            border-bottom: 4upx solid #007aff;
            position: absolute;
            left: 50%;
            bottom: 0;
            transform: translateX(-50%);
            transition: 0.3s;
        }
    }

    .current {
        color: #ffffff;
        background: rgba(64, 108, 235, 1);
        border-radius: 21upx;

        &:after {
            width: 50%;
        }
    }
}

.allOrder {
    width: 100%;
    height: 100%;
    padding: 24upx;
    margin-top: 70upx;
    box-sizing: border-box;

    .orderBox {
        // height: 370upx;
        background: #ffffff;
        margin-bottom: 24upx;
        border-radius: 10px;
        position: relative;

        .title {
            height: 72upx;
            padding-left: 24upx;
            padding-right: 24upx;
            box-sizing: border-box;
            font-size: 26upx;
            border-bottom: 1upx solid #eeeeee;
            display: flex;
            align-items: center;
            position: relative;

            .number {
                width: auto;
                height: 25upx;
                color: #333333;
                display: block;
                float: left;
            }

            .status {
                // width:78upx;
                height: 25upx;
                display: block;
                color: #f7b55f;
                position: absolute;
                right: 24upx;
            }
        }
    }
}

.image {
    image {
        width: 200upx;
        height: 200upx;
        position: absolute;
        right: -40upx;
        top: -40upx;
        z-index: 5;
        animation-name: mychange;
        animation-duration: 500ms;
    }
}

@keyframes mychange {
    0% {
        position: absolute;
        right: -20upx;
        top: -20upx;
        z-index: 5;
        transform: scale(1.3);
    }

    50% {
        position: absolute;
        right: -20upx;
        top: -20upx;
        z-index: 5;
        transform: scale(1.3);
    }

    100% {
        position: absolute;
        right: -40upx;
        top: -40upx;
        z-index: 5;
        transform: scale(1);
    }
}

.allOrder .orderBox .info {
    display: flex;
    padding: 8px 12px;
    flex-wrap: wrap;
    border-bottom: 1upx solid #eeeeee;

    .con {
        width: 50%;
        height: 45upx;
        line-height: 45upx;
        display: flex;
        align-items: center;

        .txt1 {
            position: relative;
            flex: 0 4rem;
            font-size: 24upx;
            color: #666666;
        }

        .txt1::after {
            position: absolute;
            content: ":";
            right: 8px;
        }

        .txt2 {
            flex: 1;
            font-size: 24upx;
            color: #666666;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
        }
    }
}

.allOrder .orderBox .detail {
    width: 100%;
    height: 72upx;
    padding-left: 24upx;
    padding-right: 24upx;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    position: relative;

    text {
        width: 4rem;
        height: 25upx;
        display: block;
        font-size: 26upx;
        color: #666666;
    }

    image {
        width: 32upx;
        height: 32upx;
        display: block;
        position: absolute;
        right: 24upx;
    }
}

// 筛选框
.searchDrawer {
    margin: 0;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    overflow: hidden;
    z-index: 993;

}

.content {
    background: #f3f7fa;
    width: 100%;
    height: 100vh;
    overflow: hidden;

    .search_list {
        margin-top: 10upx;
        padding: 10px;

        .search_title {
            width: 100%;
            font-size: 26upx;
            color: #000;
            font-weight: 500;
            font-family: PingFang SC;
            padding: 20upx 24upx;
            box-sizing: border-box;
            display: block;
            font-weight: 600;

        }

        .search_type {
            box-sizing: border-box;
            display: flex;
            justify-content: left;
            flex-wrap: wrap;

            .view_box {
                width: 154upx;
                height: 66upx;
                display: flex;
                justify-content: center;
                align-items: center;

                margin-top: 16upx;
                margin-right: 16upx;
                font-size: 24upx;
                white-space: wrap;
                color: #666666;
                background: #f6f6f6;
                border-radius: 5px;
                border: 1upx solid #f6f6f6;

                text {
                    text-align: center;
                }
            }

            //选中状态
            .actived {
                background: #eef2ff !important;
                border: 1upx solid #406ceb;
                color: #406ceb !important;
            }
        }
    }

    .scroll_height {
        height: calc(100vh - 150px);
        overflow: auto;

    }
}

.btn {
    width: 100%;
    height: 73upx;
    position: absolute;
    bottom: 33upx;
    display: flex;
    justify-content: center;
    bottom: 10px;
    left: 0;
    right: 0;

    button {
        width: 214upx;
        height: 73upx;
        line-height: 73upx;
        font-size: 28upx;
        border-radius: 37px;
    }

    .reset {
        color: #406ceb;
        border: 1px solid rgba(64, 108, 235, 1);
        background: #ffffff;
    }

    .save {
        background: #406ceb;
        color: #ffffff;
    }
}
</style>
